﻿var SCALE = 0.8;
var NAV_MARGIN = 65;
var MIN_FLASH_WIDTH = 1150 * SCALE;
var PAGE_HEIGHT = 625 * SCALE;

$(document).ready(function(){
	
	var flashvars = { tradeLink: "http://trade.cocowai.com/" };
	var params = { bgcolor: "#FFFFFF", AllowScriptAccess: "always", allowFullScreen: "true" };
	var attributes = {};
	
	var date = new Date();
	var ck = date.getTime();
	
	swfobject.embedSWF(
		"assets/swf/cocowai.swf?ck=" + ck, 
		"content", 
		920, 
		565, 
		"9.0.0", 
		"assets/swf/expressInstall.swf",
		flashvars,
		params,
		attributes
	);
	
	$(window).resize(onResize);
	onResize();
	
});

function onResize(){
	var margin = ($(window).height() - 565 - 25) / 2;
	if(margin < 0){
		margin = 0;
	}
	$("body").css("padding-top", margin + "px");
	//$("#content").css("height", calcFlashHeight() + "px");
	//$("#content").css("width", calcFlashWidth() + "px");
}

function calcFlashWidth(){
	var fwidth = $(window).width();
	if(fwidth < MIN_FLASH_WIDTH){
		fwidth = MIN_FLASH_WIDTH;	
	}
	return fwidth;
}

function calcFlashHeight(){
	var ratio = 1;
	var fWidth = calcFlashWidth();
	if (fWidth > MIN_FLASH_WIDTH) {
		ratio = fWidth / MIN_FLASH_WIDTH;
	}
	var fHeight = NAV_MARGIN + (PAGE_HEIGHT * ratio);
	if(fHeight < $(window).height()){
		fHeight = $(window).height();
	}
	return fHeight;
}

function setHeight(newHeight){
	if(newHeight < $(window).height()){
		newHeight = $(window).height();
	}
	$("#content").css("height", newHeight + "px");
}